package conterlles

import (
	"day12_10_homework/models/mysql"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
)

func UpdateVideo(c *gin.Context) {
	value, _ := c.Get("userId")
	s := value.(string)
	id, _ := strconv.Atoi(s)
	name := c.PostForm("name")
	time := c.PostForm("time")
	intro := c.PostForm("intro")
	url := c.PostForm("url")
	videoId := c.PostForm("videoId")
	videoIds, _ := strconv.Atoi(videoId)
	video := mysql.Video{
		UserId: id,
		Name:   name,
		Time:   time,
		Intro:  intro,
		URL:    url,
	}
	err := mysql.Update(videoIds, id, &video)
	if err != nil {
		c.JSON(http.StatusOK, JsonRes{
			Code:    500,
			Message: "修改失败",
			Data:    nil,
		})
		return
	}
	c.JSON(http.StatusOK, JsonRes{
		Code:    200,
		Message: "修改成功",
		Data:    nil,
	})
}
